﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using XiaWorld;

namespace WritingBooks
{
    // Token: 0x0200022E RID: 558
    [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
    public class JobWrite : JobBase
    {
        // Token: 0x06000B65 RID: 2917 RVA: 0x00002A3D File Offset: 0x00000C3D
        protected override void OnInit(params object[] objs)
        {
        }

        // Token: 0x06000B66 RID: 2918 RVA: 0x00002E0C File Offset: 0x0000100C
        protected override bool OnCheckFaildCondition()
        {
            return true;
        }

        // Token: 0x06000B67 RID: 2919 RVA: 0x00058498 File Offset: 0x00056698
        protected override void OnEnterJob(KStateQUnit unit)
        {
            ItemThing itemThing = ThingMgr.Instance.FindThingByID((this.CMD as CommandWrite).ItemId) as ItemThing;
            if (itemThing != null)
            {
                itemThing.Lock.UnLockAllByOwner(this.CMD);
            }
        }

        // Token: 0x06000B68 RID: 2920 RVA: 0x000584E0 File Offset: 0x000566E0
        protected override List<ToilBase> GetToilList()
        {
            ItemThing itemThing = ThingMgr.Instance.FindThingByID((this.CMD as CommandWrite).ItemId) as ItemThing;
            CommandWrite commadfWrite = this.CMD as CommandWrite;
            return new List<ToilBase>
            {
                new ToilLockThing(itemThing, 1, false, null),
                ToilGoto.GotoGrid(itemThing.Key, g_emPathEndMode.Touch, null),
                new ToilLockThing(itemThing, 1, true, null),
                new ToilPickUp(itemThing, 1, 0, false, false),
                new ToilWriting(commadfWrite.EId),
                new ToilJump2Building(null, 0, true)
            };
        }

        // Token: 0x06000B69 RID: 2921 RVA: 0x00002A3D File Offset: 0x00000C3D
        protected override void OnToilFinish(ToilBase toil, g_emJobToilState state)
        {
        }

        // Token: 0x06000B6A RID: 2922 RVA: 0x000585C4 File Offset: 0x000567C4
        protected override void OnLeaveJob(KStateQUnit unit)
        {
            if (this.CMD != null)
            {
                this.CMD.FinishCommand(false, false);
            }
            ItemThing itemThing = base.Worker.PutDownItem(0);
            if (itemThing != null)
            {
                base.Worker.map.DropItem(itemThing, base.Worker.Key, true, true, false, false, 0f);
            }
            base.Worker.JumpOutFromBuilding(false);
        }
    }
}
